package com.fr.report.core.barcode.line.code128;

import com.fr.report.core.barcode.BarcodeException;
import com.fr.report.core.barcode.CompositeModule;
import com.fr.report.core.barcode.Module;
import java.text.StringCharacterIterator;

public class UCCEAN128Barcode extends Code128Barcode
{
  public static final String SSCC_18_AI = "00";
  public static final String SCC_14_AI = "01";
  public static final String GTIN_AI = "01";
  public static final String EAN128_AI = "01";
  public static final String SHIPMENT_ID_AI = "402";
  public static final String USPS_AI = "420";
  private final String applicationIdentifier;
  private String originalData;
  private final boolean includeCheckDigit;

  public UCCEAN128Barcode(String paramString1, String paramString2)
    throws BarcodeException
  {
    this(paramString1, paramString2, true);
  }

  public UCCEAN128Barcode(String paramString1, String paramString2, boolean paramBoolean)
    throws BarcodeException
  {
    super("Ê" + paramString1 + paramString2 + getMod10CheckDigit(paramString2, paramBoolean), 2);
    if ((paramString1 == null) || (paramString1.length() == 0))
      throw new IllegalArgumentException("Application Identifier must be provided");
    this.applicationIdentifier = paramString1;
    this.originalData = paramString2;
    this.includeCheckDigit = paramBoolean;
  }

  protected Module getPreAmble()
  {
    CompositeModule localCompositeModule = new CompositeModule();
    localCompositeModule.add(QUIET_SECTION);
    localCompositeModule.add(START_C);
    return localCompositeModule;
  }

  protected String getLabel()
  {
    return '(' + this.applicationIdentifier + ") " + this.originalData + getMod10CheckDigit(this.originalData, this.includeCheckDigit);
  }

  static String getMod10CheckDigit(String paramString, boolean paramBoolean)
  {
    if (!(paramBoolean))
      return "";
    Accumulator localAccumulator1 = new Accumulator(START_INDICES[2]);
    Accumulator localAccumulator2 = new Accumulator(1);
    CharBuffer localCharBuffer = new CharBuffer(BUF_SIZES[2]);
    StringCharacterIterator localStringCharacterIterator = new StringCharacterIterator(paramString);
    int i = localStringCharacterIterator.first();
    while (i != 65535)
    {
      localCharBuffer.addChar(i);
      if (localCharBuffer.isFull())
      {
        int k = ModuleFactory.getIndex(localCharBuffer.toString(), 2);
        localAccumulator1.add(k * localAccumulator2.getValue());
        localAccumulator2.increment();
        localCharBuffer.clear();
      }
      int j = localStringCharacterIterator.next();
    }
    return String.valueOf(localAccumulator1.getValue() % 10);
  }
}